package key_secret

import (
	"crypto/sha1"
	"encoding/base64"
	"fmt"
	"strings"
)

func VerifySecret(key, tenantID, secret string) bool {
	byteSecret, err := base64.StdEncoding.DecodeString(secret)
	if err != nil {
		return false
	}

	secretArr := strings.Split(string(byteSecret), ".@.")
	sha1Source := []byte(key + tenantID + secretArr[1])
	sha1Str := fmt.Sprintf("%x", sha1.Sum(sha1Source))
	if sha1Str == secretArr[0] {
		return true
	}

	return false
}
